package com.feri.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feri.api.dao.MoodlikeDao;
import com.feri.api.service.intf.MoodlikeService;
import com.feri.api.util.TokenUtil;
import com.feri.api.vo.R;
import com.feri.common.entity.Moodlike;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lr
 * @date 2022/10/3
 */
@Service
public class MoodlikeServiceImpl implements MoodlikeService {
    @Autowired
    private MoodlikeDao dao;

    @Override
    public R save(Long mid, String token) {
        Long a= TokenUtil.toLong(token);
        if (mid>0&&a>0){
            if (dao.insert(new Moodlike(a,mid))>0){
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public R queryAll() {
        return null;
    }

    @Override
    public R delete(Long mid, String token) {
        Long a= TokenUtil.toLong(token);
        if (mid>0&&a>0){
            if (dao.delete(new QueryWrapper<Moodlike>().eq("mid",mid).eq("uid",a))>0){
                return R.ok();
            }
        }
        return R.fail();
    }
}
